home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2001 May / SGI IRIX Base Documentation 2001 May.iso / usr / share / catman / p_man / cat3g / glob.z / glob
Encoding:
Text File  |  2001-04-17  |  17.9 KB  |  330 lines

  1.  
  2.  
  3.  
  4. gggglllloooobbbb((((3333GGGG))))                                                              gggglllloooobbbb((((3333GGGG))))
  5.  
  6.  
  7.  
  8. NNNNAAAAMMMMEEEE
  9.      _gggg_llll_oooo_bbbb - generate pathnames matching a pattern
  10.  
  11. SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  12.      _####_iiii_nnnn_cccc_llll_uuuu_dddd_eeee _<<<<_gggg_llll_oooo_bbbb_...._hhhh_>>>>
  13.      _iiii_nnnn_tttt _gggg_llll_oooo_bbbb_((((_cccc_oooo_nnnn_ssss_tttt _cccc_hhhh_aaaa_rrrr _****_pppp_aaaa_tttt_tttt_eeee_rrrr_nnnn_,,,, _iiii_nnnn_tttt _ffff_llll_aaaa_gggg_ssss_,,,,
  14.          _iiii_nnnn_tttt_((((_****_eeee_rrrr_rrrr_ffff_uuuu_nnnn_cccc_))))_((((_cccc_oooo_nnnn_ssss_tttt _cccc_hhhh_aaaa_rrrr _****_eeee_pppp_aaaa_tttt_hhhh_,,,, _iiii_nnnn_tttt _eeee_eeee_rrrr_rrrr_nnnn_oooo_))))_,,,,
  15.              gggglllloooobbbb____tttt ****ppppgggglllloooobbbb))));;;;
  16.  
  17.      vvvvooooiiiidddd gggglllloooobbbbffffrrrreeeeeeee((((gggglllloooobbbb____tttt ****ppppgggglllloooobbbb))));;;;
  18.  
  19. DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  20.      The structure type gggglllloooobbbb____tttt is defined in the header _<<<<_gggg_llll_oooo_bbbb_...._hhhh_>>>> and includes
  21.      at least the following members:
  22.  
  23.      MemberType  MemberName Description
  24.      _______________________________________________________________
  25.      ssssiiiizzzzeeee____tttt      ggggllll____ooooffffffffssss    SSSSlllloooottttssss ttttoooo rrrreeeesssseeeerrrrvvvveeee aaaatttt ssssttttaaaarrrrtttt ooooffff ggggllll____ppppaaaatttthhhhvvvv....
  26.      cccchhhhaaaarrrr ********     ggggllll____ppppaaaatttthhhhvvvv   PPPPooooiiiinnnntttteeeerrrr ttttoooo lllliiiisssstttt ooooffff mmmmaaaattttcccchhhheeeedddd ppppaaaatttthhhhnnnnaaaammmmeeeessss....
  27.      ssssiiiizzzzeeee____tttt      ggggllll____ppppaaaatttthhhhcccc   CCCCoooouuuunnnntttt ooooffff ppppaaaatttthhhhssss mmmmaaaattttcccchhhheeeedddd bbbbyyyy ppppaaaatttttttteeeerrrrnnnn....
  28.  
  29.      The argument _p_a_t_t_e_r_n is a pointer to a pathname pattern to be expanded.
  30.      The _gggg_llll_oooo_bbbb function matches all accessible pathnames against this pattern
  31.      and develops a list of all pathnames that match.  In order to have access
  32.      to a pathname, _gggg_llll_oooo_bbbb requires search permission on every component of a
  33.      path except the last, and read permission on each directory of any
  34.      filename component of _p_a_t_t_e_r_n that contains any of the following
  35.      characters:
  36.  
  37.           *     ?      [
  38.  
  39.      The _gggg_llll_oooo_bbbb function stores the number of matched pathnames into
  40.      ppppgggglllloooobbbb---->>>>ggggllll____ppppaaaatttthhhhcccc and a pointer to a list of pointers to pathnames into
  41.      ppppgggglllloooobbbb---->>>>ggggllll____ppppaaaatttthhhhvvvv.... The pathnames are in sort order as defined by the
  42.      current setting of the LC_COLLATE category.  The first pointer after the
  43.      last pathname is a null pointer.  If the pattern does not match any
  44.      pathnames, the returned number of matched paths is set to zero, and the
  45.      contents of ppppgggglllloooobbbb---->>>>ggggllll____ppppaaaatttthhhhvvvv are undetermined.
  46.  
  47.      It is the caller's responsibility to create the structure pointed to by
  48.      _gggg_llll_oooo_bbbb.  _gggg_llll_oooo_bbbb allocates other space as needed, including the memory pointed
  49.      to by ggggllll____ppppaaaatttthhhhvvvv.... The _gggg_llll_oooo_bbbb_ffff_rrrr_eeee_eeee function frees any space associated with
  50.      _gggg_llll_oooo_bbbb from a previous call to _gggg_llll_oooo_bbbb.
  51.  
  52.      The _f_l_a_g_s argument is used to control the behaviour of _gggg_llll_oooo_bbbb.  The value
  53.      of _f_l_a_g_s is a bitwise inclusive OR of zero or more of the following
  54.      constants, which are defined in the header _<<<<_gggg_llll_oooo_bbbb_...._hhhh_>>>>:
  55.  
  56.      _G_L_O_B__A_P_P_E_N_D
  57.  
  58.           Append pathnames generated to the ones from a previous call to _gggg_llll_oooo_bbbb.
  59.  
  60.  
  61.                                                                         PPPPaaaaggggeeee 1111
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68. gggglllloooobbbb((((3333GGGG))))                                                              gggglllloooobbbb((((3333GGGG))))
  69.  
  70.  
  71.  
  72.      _G_L_O_B__D_O_O_F_F_S
  73.  
  74.           Make use of ppppgggglllloooobbbb---->>>>ggggllll____ooooffffffffssss.... If this flag is set, ppppgggglllloooobbbb---->>>>ggggllll____ooooffffffffssss is
  75.           used to specify how many null pointers to add to the beginning of
  76.           ppppgggglllloooobbbb---->>>>ggggllll____ppppaaaatttthhhhvvvv.... In other words, ppppgggglllloooobbbb---->>>>ggggllll____ppppaaaatttthhhhvvvv will point to
  77.           ppppgggglllloooobbbb---->>>>ggggllll____ooooffffffffssss null pointers, followed by ppppgggglllloooobbbb---->>>>ggggllll____ppppaaaatttthhhhcccc pathname
  78.           pointers, followed by a null pointer.
  79.  
  80.      _G_L_O_B__E_R_R
  81.  
  82.           Causes _gggg_llll_oooo_bbbb to return when it encounters a directory that it cannot
  83.           open or read.  Ordinarily, _gggg_llll_oooo_bbbb continues to find matches.
  84.  
  85.      _G_L_O_B__M_A_R_K
  86.  
  87.           Each pathname that is a directory that matches _p_a_t_t_e_r_n has a slash
  88.           appended.
  89.  
  90.      _G_L_O_B__N_O_C_H_E_C_K
  91.  
  92.           If _p_a_t_t_e_r_n does not match any pathname, then _gggg_llll_oooo_bbbb returns a list
  93.           consisting of only _p_a_t_t_e_r_n, and the number of matched pathnames is
  94.           one (1).
  95.  
  96.      _G_L_O_B__N_O_E_S_C_A_P_E
  97.  
  98.           Disable backslash escaping.
  99.  
  100.      _G_L_O_B__N_O_S_O_R_T
  101.  
  102.           Ordinarily, _gggg_llll_oooo_bbbb sorts the matching pathnames according to the
  103.           current setting of the LC_COLLATE category.  When this flag is used
  104.           the order of pathnames returned is unspecified.
  105.  
  106.      The GLOB_APPEND flag can be used to append a new set of pathnames to
  107.      those found in a previous call to _gggg_llll_oooo_bbbb.  The following rules apply when
  108.      two or more calls to _gggg_llll_oooo_bbbb are made with the same value of _p_g_l_o_b and
  109.      without intervening calls to _gggg_llll_oooo_bbbb_ffff_rrrr_eeee_eeee:
  110.  
  111.        The first such call must not set GLOB_APPEND.  All subsequent calls
  112.        must set it.
  113.  
  114.        All the calls must set GLOB_DOOFFS, or all must not set it.
  115.  
  116.        After the second call, ppppgggglllloooobbbb---->>>>ggggllll____ppppaaaatttthhhhvvvv points to a list containing the
  117.        following:
  118.  
  119.           Zero or more null pointers, as specified by GLOB_DOOFFS and
  120.           ppppgggglllloooobbbb---->>>>ggggllll____ooooffffffffssss....
  121.  
  122.           Pointers to the pathnames that were in the ppppgggglllloooobbbb---->>>>ggggllll____ppppaaaatttthhhhvvvv list
  123.           before the call, in the same order as before.
  124.  
  125.  
  126.  
  127.                                                                         PPPPaaaaggggeeee 2222
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134. gggglllloooobbbb((((3333GGGG))))                                                              gggglllloooobbbb((((3333GGGG))))
  135.  
  136.  
  137.  
  138.           Pointers to the new pathnames generated by the second call, in the
  139.           specified order.
  140.  
  141.        The count returned in ppppgggglllloooobbbb---->>>>ggggllll____ppppaaaatttthhhhcccc will be the total number of
  142.        pathnames from the two calls.
  143.  
  144.        The application can change any of the fields after a call to _gggg_llll_oooo_bbbb.  If
  145.        it does, it must reset them to the original value before a subsequent
  146.        call, using the same _p_g_l_o_b value, to _gggg_llll_oooo_bbbb_ffff_rrrr_eeee_eeee or _gggg_llll_oooo_bbbb with the
  147.        GLOB_APPEND flag.
  148.  
  149.      If, during the search, a directory is encountered that cannot be opened
  150.      or read and _e_r_r_f_u_n_c is not a null pointer, _gggg_llll_oooo_bbbb calls (*_e_r_r_f_u_n_c()) with
  151.      two arguments:
  152.  
  153.        The _e_p_a_t_h argument is a pointer to the path that failed.
  154.  
  155.        The _e_e_r_r_n_o argument is the value of _e_r_r_n_o from that failure, as set by
  156.        _o_p_e_n_d_i_r(), _r_e_a_d_d_i_r() or _s_t_a_t().  (Other values may be used to report
  157.        other errors not explicitly documented for those functions.)
  158.  
  159.      The following constants are defined as error return values for _gggg_llll_oooo_bbbb:
  160.  
  161.      _G_L_O_B__A_B_O_R_T_E_D
  162.  
  163.           The scan was stopped because GLOB_ERR was set or (*_e_r_r_f_u_n_c())
  164.           returned non-zero.
  165.  
  166.      _G_L_O_B__N_O_M_A_T_C_H
  167.  
  168.           The pattern does not match any existing pathname, and GLOB_NOCHECK
  169.           was not set in flags.
  170.  
  171.      _G_L_O_B__N_O_S_P_A_C_E
  172.  
  173.           An attempt to allocate memory failed.
  174.  
  175.      If (*_e_r_r_f_u_n_c()) is called and returns non-zero or if the GLOB_ERR flag is
  176.      set in _f_l_a_g_s, _gggg_llll_oooo_bbbb stops the scan and returns GLOB_ABORTED after setting
  177.      _g_l__p_a_t_h_v in _p_g_l_o_b to reflect the paths already scanned.  If GLOB_ERR is
  178.      not set and either _e_r_r_f_u_n_c is a null pointer or (*_e_r_r_f_u_n_c()) returns
  179.      zero, the error is ignored.
  180.  
  181. RRRREEEETTTTUUUURRRRNNNN VVVVAAAALLLLUUUUEEEE
  182.      On successful completion, _gggg_llll_oooo_bbbb returns zero.  The argument
  183.      ppppgggglllloooobbbb---->>>>ggggllll____ppppaaaatttthhhhcccc returns the number of matched pathnames and the argument
  184.      ppppgggglllloooobbbb---->>>>ggggllll____ppppaaaatttthhhhvvvv contains a pointer to a null-terminated list of matched
  185.      and sorted pathnames.  However, if ppppgggglllloooobbbb---->>>>ggggllll____ppppaaaatttthhhhcccc is zero, the contents
  186.      of ppppgggglllloooobbbb---->>>>ggggllll____ppppaaaatttthhhhvvvv is undefined.
  187.  
  188.      The _gggg_llll_oooo_bbbb_ffff_rrrr_eeee_eeee function returns no value.
  189.  
  190.  
  191.  
  192.  
  193.                                                                         PPPPaaaaggggeeee 3333
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200. gggglllloooobbbb((((3333GGGG))))                                                              gggglllloooobbbb((((3333GGGG))))
  201.  
  202.  
  203.  
  204.      If _gggg_llll_oooo_bbbb terminates due to an error, it returns one of the non-zero
  205.      constants defined in _<<<<_gggg_llll_oooo_bbbb_...._hhhh_>>>>.  The arguments ppppgggglllloooobbbb---->>>>ggggllll____ppppaaaatttthhhhcccc and
  206.      ppppgggglllloooobbbb---->>>>ggggllll____ppppaaaatttthhhhvvvv are still set as defined above.
  207.  
  208. EEEEXXXXAAAAMMMMPPPPLLLLEEEESSSS
  209.      One use of the GLOB_DOOFFS flag is by applications that build an argument
  210.      list for use with _eeee_xxxx_eeee_cccc_vvvv, _eeee_xxxx_eeee_cccc_vvvv_eeee or _eeee_xxxx_eeee_cccc_vvvv_pppp.  Suppose, for example, that an
  211.      application wants to do the equivalent of:
  212.  
  213.              _llll_ssss _----_llll _****_...._cccc
  214.  
  215.      But for some reason:
  216.  
  217.              _ssss_yyyy_ssss_tttt_eeee_mmmm_((((_""""_llll_ssss _----_llll _****_...._cccc_""""_))))
  218.  
  219.      is not acceptable.  The application could obtain approximately the same
  220.      result using the sequence:
  221.  
  222.           gggglllloooobbbbbbbbuuuuffff....ggggllll____ooooffffffffssss ==== 2222;;;;
  223.           gggglllloooobbbb ((((""""****....cccc"""",,,, GGGGLLLLOOOOBBBB____DDDDOOOOOOOOFFFFFFFFSSSS,,,, NNNNUUUULLLLLLLL,,,, &&&&gggglllloooobbbbbbbbuuuuffff))));;;;
  224.           gggglllloooobbbbbbbbuuuuffff....ggggllll____ppppaaaatttthhhhvvvv[[[[0000]]]] ====""""llllssss"""";;;;
  225.           gggglllloooobbbbbbbbuuuuffff....ggggllll____ppppaaaatttthhhhvvvv[[[[1111]]]] ====""""----llll"""";;;;
  226.           eeeexxxxeeeeccccpppp ((((""""llllssss"""",,,, &&&&gggglllloooobbbbbbbbuuuuffff....ggggllll____ppppaaaatttthhhhvvvv[[[[0000]]]]))));;;;
  227.  
  228.      Using the same example:
  229.  
  230.              _llll_ssss _----_llll _****_...._cccc _****_...._hhhh
  231.  
  232.      could be approximately simulated using GLOB_APPEND as follows:
  233.  
  234.           gggglllloooobbbbbbbbuuuuffff....ggggllll____ooooffffffffssss ==== 2222;;;;
  235.           gggglllloooobbbb ((((""""****....cccc"""",,,, GGGGLLLLOOOOBBBB____DDDDOOOOOOOOFFFFFFFFSSSS,,,, NNNNUUUULLLLLLLL,,,, &&&&gggglllloooobbbbbbbbuuuuffff))));;;;
  236.           gggglllloooobbbb ((((""""****....hhhh"""",,,, GGGGLLLLOOOOBBBB____DDDDOOOOOOOOFFFFFFFFSSSS||||GGGGLLLLOOOOBBBB____AAAAPPPPPPPPEEEENNNNDDDD,,,, NNNNUUUULLLLLLLL,,,, &&&&gggglllloooobbbbbbbbuuuuffff))));;;;
  237.            ...
  238.  
  239. AAAAPPPPPPPPLLLLIIIICCCCAAAATTTTIIIIOOOONNNN UUUUSSSSAAAAGGGGEEEE
  240.      This function is not provided for the purpose of enabling utilities to
  241.      perform pathname expansion on their arguments, as the operation is
  242.      performed by the shell, and utilities are explicitly not expected to redo
  243.      this.  Instead, it is provided for applications that need to do pathname
  244.      expansion on strings obtained from other sources, such as a pattern typed
  245.      by a user or read from a file.
  246.  
  247.      If a utility needs to see if a pathname matches a given pattern, it can
  248.      use _ffff_nnnn_mmmm_aaaa_tttt_cccc_hhhh.
  249.  
  250.      Note that ggggllll____ppppaaaatttthhhhcccc and ggggllll____ppppaaaatttthhhhvvvv have meaning even if _gggg_llll_oooo_bbbb fails.  This
  251.      allows _gggg_llll_oooo_bbbb to report partial results in the event of an error.  However,
  252.      if ggggllll____ppppaaaatttthhhhcccc is zero, ggggllll____ppppaaaatttthhhhvvvv is unspecified even if _gggg_llll_oooo_bbbb did not return
  253.      an error.
  254.  
  255.      The GLOB_NOCHECK option could be used when an application wants to expand
  256.  
  257.  
  258.  
  259.                                                                         PPPPaaaaggggeeee 4444
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266. gggglllloooobbbb((((3333GGGG))))                                                              gggglllloooobbbb((((3333GGGG))))
  267.  
  268.  
  269.  
  270.      a pathname if wildcards are specified, but wants to treat the pattern as
  271.      just a string otherwise.  The _ssss_hhhh utility might use this for option-
  272.      arguments, for example.
  273.  
  274.      The new pathnames generated by a subsequent call with GLOB_APPEND are not
  275.      sorted together with the previous pathnames.  This mirrors the way that
  276.      the sheel handles pathname expansion when multiple expansions are done on
  277.      a command line.
  278.  
  279.      Applications that need tilde and parameter expansion should use _wwww_oooo_rrrr_dddd_eeee_xxxx_pppp.
  280.  
  281. SSSSEEEEEEEE AAAALLLLSSSSOOOO
  282.      execv(2), fnmatch(3g), opendir(3b), readdir(3b), stat(2), wordexp(3g),
  283.      _<<<<_gggg_llll_oooo_bbbb_...._hhhh_>>>>.
  284.  
  285.  
  286.  
  287.  
  288.  
  289.  
  290.  
  291.  
  292.  
  293.  
  294.  
  295.  
  296.  
  297.  
  298.  
  299.  
  300.  
  301.  
  302.  
  303.  
  304.  
  305.  
  306.  
  307.  
  308.  
  309.  
  310.  
  311.  
  312.  
  313.  
  314.  
  315.  
  316.  
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.                                                                         PPPPaaaaggggeeee 5555
  326.  
  327.  
  328.  
  329.